home *** CD-ROM | disk | FTP | other *** search
- Path: sparc13.ncu.edu.tw!s3032089
- From: s3032089@sparc13.ncu.edu.tw (Alexander PeaceLand)
- Newsgroups: comp.lang.c
- Subject: Re: Do you see what is wrong?
- Date: Fri, 15 Mar 1996 09:32:28 GMT
- Organization: NCU ME
- Message-ID: <s3032089.14.3149392B@sparc13.ncu.edu.tw>
- References: <4i72h6$2d4@blaze.cs.jhu.edu>
- NNTP-Posting-Host: @140.115.65.133
-
- >Can someone point out what is wrong with this snippet of code?
- >The problem is that I get a segmentation fault(core dumped) error when I
- >hit ^d to send end of file. the error occurs at the place specified in
- >the code. I would appreciate any/all ideas and any fixes that you might
- >suggest. This was compiled on a system running some flavor of UNIX (not
- >sure which)
-
-
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <math.h>
-
- >#define SIZE 200
-
- >int closest(float [], float [], int [], float [], int);
- >float distance(float, float, float, float);
-
- >void main()
- >{
- >float xtemp, ytemp, Xposition[SIZE], Yposition[SIZE], totalLength[1];
- >int j = -1, n, i, distance, nextCoord, current = 0, status[SIZE];
-
- >totalLength[1] = 0;
-
- >/* variables not used in this section are used in other non-relevant
- >parts of the code */
-
- >printf("Enter coordinates in the form: x y\n ");
-
- >for( n = 0; n < SIZE; n++, j++ ) {
- > if( scanf("%f%f", &xtemp, &ytemp) != EOF)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- I don't know if scanf could used like this.
- But I have found that when your data formats you pass to scanf is
- different from the one you assigned in scanf, the scanf will be DAMAGED!
- (I use Turbo C 2.0)
- Especailly in loop, when the scanf damaged, scanf will not wait for your
- input anymore.
-
- > {
- > Xposition[n] = xtemp;
- > Yposition[n] = ytemp;
- > }
- > else {
- > printf("Done entering Numbers");
- > n = SIZE;
- > printf("\n%f %f", Xposition[j], Yposition[j]);
- > } /* <== I get a core dump right here. _after_ executing the
- >stuff in the else statemnet */
- > }
- >}
-
-
- o----------------------------------------------------------o
- | (''') |
- | ( 0 0 ) E-mail address : s3032089@sparc13.ncu.edu.tw |
- | ----- |
- | ||||| - Alexander PeaceLand - |
- o----------------------------------------------------------o
-